
package com.eworking.eim.user;

import android.os.Parcel;
import android.os.Parcelable;

public class EIMUser implements Parcelable {
    
    /** 身份标识 */
    protected String JID;
    
    /** 用户账号 */
    protected String account;
    
    /** 昵称 */
    protected String nickname;
    
    public static final Parcelable.Creator<EIMUser> CREATOR = new Parcelable.Creator<EIMUser>() {
        
        @Override
        public EIMUser createFromParcel(Parcel parcel) {
            return new EIMUser(parcel);
        }
        
        @Override
        public EIMUser[] newArray(int size) {
            return new EIMUser[size];
        }
    };
    protected EIMUser(){
    	
    }
    /**
     * 实例化EIMUser对象
     * 
     * @param parcel
     */
    public EIMUser(Parcel parcel) {
        this.JID = parcel.readString();
        this.account = parcel.readString();
        this.nickname = parcel.readString();
    }
    
    /**
     * 实例化EIMUser对象
     * 
     * @param eid 企业ID
     * @param username 用户名称
     */
    public EIMUser(String JID, String account) {
        this.JID = JID;
        if (account.contains("@")) {
            // 根据用户JID获取用户账号
            this.account = EIMAccountUtils.getAccountFromJID(account);
        } else {
            this.account = account;
        }
    }
    
    /**
     * 实例化EIMUser对象
     * 
     * @param str 用户名称or企业ID
     */
    public EIMUser(String account) {
        if (account.contains("@")) {
            this.JID = account;
            // 根据用户JID获取用户账号
            this.account = EIMAccountUtils.getAccountFromJID(account);
        } else {
            this.account = account;
            // 根据用户账号获取用户JID
            this.JID = EIMAccountUtils.getJIDFromAccount(account);
        }
    }
    
    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeString(this.JID);
        parcel.writeString(this.account);
        parcel.writeString(this.nickname);
    }
    
    @Override
    public int describeContents() {
        return 0;
    }
    
    public String getJID() {
        return JID;
    }
    
    public void setJID(String jID) {
        JID = jID;
    }
    
    public String getAccount() {
        return account;
    }
    
    public void setAccount(String account) {
        this.account = account;
    }
    
    public String getNickname() {
        if (this.nickname == null) {
            return this.account;
        }
        return nickname;
    }
    
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
}
